package com.aaa.mbs.service.impl;

import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.mbs.dao.LocalMessageDao;
import com.aaa.mbs.entity.LocalMessage;
import com.aaa.mbs.service.LocalMessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (LocalMessage)表服务实现类
 *
 * @author makejava
 * @since 2021-01-22 14:36:49
 */
@Service("localMessageService")
public class LocalMessageServiceImpl implements LocalMessageService {
    @Resource
    private LocalMessageDao localMessageDao;

    /**
     * 通过ID查询单条数据
     *
     * @return 实例对象
     */
    @Override
    public LocalMessage queryById(Integer id) {
        return this.localMessageDao.queryById(id);
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @param localMessage 实例对象
     * @return 对象列表
     */
    @Override
    public Result queryAll(LocalMessage localMessage) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.localMessageDao.queryAll(localMessage));
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<LocalMessage> queryAllByLimit(int offset, int limit) {
        return this.localMessageDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param localMessage 实例对象
     * @return 实例对象
     */
    @Override
    public LocalMessage insert(LocalMessage localMessage) {
        this.localMessageDao.insert(localMessage);
        return localMessage;
    }

    /**
     * 修改数据
     *
     * @param localMessage 实例对象
     * @return 实例对象
     */
    @Override
    public LocalMessage update(LocalMessage localMessage) {
        this.localMessageDao.update(localMessage);
        return this.queryById(localMessage.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.localMessageDao.deleteById(id) > 0;
    }
}